<?php


namespace app\adminapi\validate\hotel;


use app\common\model\hotel\Hotel;
use app\common\validate\BaseValidate;

/**
 * @projectName src
 */
class HotelValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkHotel',
        'pid' => 'require|checkParentHotel|different:id',
        'hotel_name' => 'require|unique:' . Hotel::class,
        'firm_name' => 'require',
        'contact_person' => 'require',
        'contact_phone' => 'require',
        'status' => 'require|in:0,1,2,3'
    ];

    protected $message = [
        'id.require' => '参数缺失',
        'pid.require' => '请填写父级酒店',
        'hotel_name.require' => '请填写酒店名称',
        'firm_name.require' => '请填写酒店公司名称',
        'contact_person.require' => '请填写联系人',
        'contact_phone.require' => '请填写联系方式',
        'status.require' => '请填写审核状态',
        'status.in' => '审核状态参数不合法'
    ];

    /**
     * @notes 添加场景
     * sceneAdd
     */
    public function sceneAdd()
    {
        return $this->only(['pid','hotel_name','firm_name','contact_person','contact_phone']);
    }

    /**
     * @notes 详情场景
     * sceneAdd
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes 编辑场景
     * sceneAdd
     */
    public function sceneEdit()
    {
    }

    /**
     * @notes 删除场景
     * sceneAdd
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    public function checkHotel($value)
    {
        $user = Hotel::findOrEmpty($value);
        if ($value !== 0 && $user->isEmpty()) {
            return '酒店ID不存在';
        }
        return true;
    }
    public function checkParentHotel($value)
    {
        $user = Hotel::findOrEmpty($value);
        if ($value !== 0 && $user->isEmpty()) {
            return '酒店父级ID不存在';
        }
        return true;
    }
}